package com.sky.controller.user;

import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "C端-订单结账相关接口")
@RequestMapping("/user/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /*
    * 订单提交数据
    * */
    @PostMapping("/submit")
    @ApiOperation("用户下单")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单：{}",ordersSubmitDTO);

        // 调用业务进行用户下单
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);

    }
    /*
    * 订单支付
    * */
    @ApiOperation("订单支付")
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}",ordersPaymentDTO);
        // 调用业务进行订单支付
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成交易单:{}",orderPaymentVO);
        return Result.success(orderPaymentVO);

    }

    /*
    * 订单查询与催单
    * */
    @ApiOperation("查询用户历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(Integer page,Integer pageSize,
                                            Integer status){
        log.info("查询用户历史订单：页码 {}，每页大小 {}，订单状态 {}",page,pageSize,status);

        //调用业务获取分页数据
        PageResult pageResult = orderService.pageQuery(page,pageSize,status);

        return Result.success(pageResult);
    }

    /*
    * 用户催单
    * */
    @ApiOperation("用户催单")
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        log.info("用户催单：{}",id);
        orderService.reminder(id);
        return Result.success();

    }



}
